package com.bawei.module_launcher.gateway

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bawei.library_common.utils.LoggerUtils
import com.bawei.module_launcher.R
import com.bawei.module_launcher.gateway.entity.GatewayEntity
import com.bw.quickadapter.BaseQuickMultipleAdapter
import com.bw.quickadapter.BaseViewHolder

/**
 * @Author : 
 * @Time : On 2023/7/20 16:23
 * @Description : GateWayAdapter
 */
class GateWayAdapter:BaseQuickMultipleAdapter<GatewayEntity>() {
    /**
     * 创建itemview
     */
    override fun createItemVIew(viewType: Int, parent: ViewGroup?): View {
        return if (viewType == 100){
            LayoutInflater.from(parent!!.context).inflate(R.layout.item_gateway_title,parent,false)
        } else{
            LayoutInflater.from(parent!!.context).inflate(R.layout.item_gateway_child,parent,false)
        }

    }
   //设置占的列数
    override fun getMultipleSpanSize(position: Int, recyclerView: RecyclerView?): Int {
       val layoutmanager = recyclerView?.layoutManager
       if (layoutmanager !is GridLayoutManager){
           return 1
       }
       if (data[position].getType() == 100){

           return 3
       }
       return 1
    }
    //绑定数据
    override fun convert(holder: BaseViewHolder?, item: GatewayEntity?) {
        item!!.let {
            if (it.getType() == 100){
                holder!!.setText(R.id.gateway_title_title,it.title)
                holder!!.setImage(R.id.gateway_title_img,it.iconId)
            }else if (it.getType() == 200){
                holder!!.setImage(R.id.gateway_child_img,it.iconId)
                holder!!.setText(R.id.gateway_child_title,it.title)
            }
        }
    }


    //返回类型 100或200
    override fun getItemType(position: Int): Int {
        return data[position].getType()
    }
}